﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Collections.Generic;

namespace Daytimer.DatabaseHelpers.Test
{
	[TestClass]
	public class ContactTest
	{
		[TestMethod]
		public void ParseVCardTest()
		{
			string vCardData = @"BEGIN:VCARD
VERSION:2.1
N;LANGUAGE=en-us:Pinch;David;John;Mr.
FN:Mr. David John Pinch
NICKNAME:Dave
ORG:Thought Project
TITLE:Dictator
NOTE:Generated with Outlook 2007.
TEL;WORK;VOICE:800-929-5805
TEL;HOME;VOICE:612-269-6017
TEL;CELL;VOICE:612-269-6017
ADR;WORK:;;;;;;United States of America
ADR;HOME;PREF:;;3247 Upton Avenue N.;Minneapolis;MN;55412;United States of America
LABEL;HOME;PREF;ENCODING=QUOTED-PRINTABLE:3247 Upton Avenue N.=0D=0A=
Minneapolis, MN 55412
X-MS-OL-DEFAULT-POSTAL-ADDRESS:1
X-WAB-GENDER:2
URL;WORK:http://www.thoughtproject.com
ROLE:Programmer
BDAY:20090414
KEY;X509;ENCODING=BASE64:
 MIICZDCCAc2gAwIBAgIQRMnJkySZCu8S15WhdyuljjANBgkqhkiG9w0BAQUFADBiMQswCQYD
 VQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UE
 AxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwHhcNMDcwNTExMTU0NTI2
 WhcNMDgwNTEwMTU0NTI2WjBJMR8wHQYDVQQDExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMSYw
 JAYJKoZIhvcNAQkBFhdkYXZlQHRob3VnaHRwcm9qZWN0LmNvbTCBnzANBgkqhkiG9w0BAQEF
 AAOBjQAwgYkCgYEAmLhq0UDsgB8paOBzXCtv9SbwccPYJhJr6f7bK3JO1xkCbKmzoLhCZUVB
 4zP5bWTBnQYpolA9t1Pbrd29flX90xizEljCuL2uOz4cFc+NoF7h0h5nFvnFVAmzsJmL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ne5ZbZV+VVPDH3FctWk+bU9mnW5Vdnufwq8S6X
 cm6tbqeNwxDqG6bhnp74r5d8R3sVzr+oz2/+rluJHQexY4r0AJpunaN9os3PmF9nQjBxya8+
 uNEfzA0dxEQ3IzxWtKHIr9DKtUU5PubnwzzLr7Z52wk/yFev6EmLSf8A66n+Qryz4c2Mmn6p
 cTXDJtaMKCpz1I/wr1bQmBs5COhkJrLEatHFOVmylrp227+/FFQeIXOFUHqaK0pR905Wzh9Z
 1P8AtdWmZiVUYxyB9MVw2ptJDqLM2MqR09+9FFe7XSVNWN6as7HU+CZI7u9u7C5BZJcSLnse
 9dLF8OWursHS7sQSMeFcZX/61FFeRXk4zdjqi/dOWuGkhlnspHDCCZ4zjoSDg4/nV/wJNC+t
 xW91Ek0UoZGV1yMjoR+VFFdc4r2TXkYSep2euafZ6ftlsrdY95+YLxnFa+iOY9MUHqSTRRXl
 PWKMZtsyNal3Tge1FFFdtKK5UZM//9k=
REV:20090825T194011Z
END:VCARD
";

			List<Contact> list = Contact.ParseVCard(new StringReader(vCardData));

			foreach (Contact each in list)
				File.Delete(ContactDatabase.ContactsAppData + "\\" + each.ID);
		}
	}
}
